package com.zyg.dao;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.zyg.pojo.Dept;
import com.zyg.pojo.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface UserMapper extends BaseMapper<User> {

    @Override
    @Select("select id,name,pass,birthday,dept_id from sys_user ${ew.customSqlSegment}")
    @Results({
            @Result(property = "id", column = "id"),
            @Result(property = "name", column = "name"),
            @Result(property = "pass", column = "pass"),
            @Result(property = "birthday", column = "birthday"),
            @Result(property = "dept", column = "dept_id", javaType = Dept.class,
                    one = @One(select = "com.zyg.dao.DeptMapper.selectById"))
    })
    List<User> selectList(IPage<User> page, @Param(Constants.WRAPPER)Wrapper<User> queryWrapper);

    @Select("select * from sys_user where name = #{name} and pass = #{pass}")
    User login(User user);

    @Insert("insert into sys_user(name,pass,birthday,dept_id) values(#{name},#{pass},#{birthday},#{deptId})")
    int add(User user);

    @Select("select * from sys_user where id = #{id}")
    User findUserById(int id);
    @Select("select id from sys_user where name = #{name} and pass = #{pass}")
    Integer findIdByUser(User user);

    @Update("update sys_user set name = #{name},pass = #{pass},birthday = #{birthday},dept_id = #{deptId} where id = #{id}")
    Integer update(User user);
}